package cn.com.generaldata.os.service.indicator_evaluation.incr_analysis;

import org.apache.commons.lang3.Validate;
import org.nutz.dao.sql.Criteria;

import cn.com.generaldata.jsme_indicator_system.entity.IndicatorEvaluation;
import cn.com.generaldata.jsme_indicator_system.util.Constants;
import cn.com.generaldata.os.service.indicator_evaluation.IndicatorEvaluationCalculateService;
import cn.com.generaldata.os.vo.IndicatorAccountVO;

/**
 * 固定资本形成额可比价评估指标计算类.
 */
public class FixedAssetsComparablePriceCalculateService extends IndicatorEvaluationCalculateService {
	// 基期固定资本形成额现价（2001年的现价）
	private double baseComparablePrice = 3543.16;

	private String exponentIndicatorName = "江苏固定资本形成额指数";

	@Override
	protected Double calculate(IndicatorEvaluation indicator, IndicatorAccountVO indicatorAccountVO) {
		Double result = null;
		if (indicator.getSection() == Constants.INDICATOR_LEVEL_PROVINCE) {
			result = calculateProvinceResult(indicator, indicatorAccountVO);
		} else if (indicator.getSection() == Constants.INDICATOR_LEVEL_CITY) {
			// 市指标没确定先保留
		}
		return result;
	}

	private Double calculateProvinceResult(IndicatorEvaluation indicator, IndicatorAccountVO indicatorAccountVO) {
		double exponent = getExponent(indicatorAccountVO);

		return baseComparablePrice * exponent / 100;
	}

	private Double getExponent(IndicatorAccountVO indicatorAccountVO) {
		Integer indicatorId = getIndicatorInputId(exponentIndicatorName, null);
		Criteria cri = getIndicatorDataCri(indicatorAccountVO, indicatorAccountVO.getYear(), indicatorId);

		Double result = getInputIndicatorValue(cri);
		Validate.isTrue(result != null);
		return result;
	}

}
